package com.lsc.fegin.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lsc.admin.demo.api.UserService;
import com.lsc.fegin.bo.FeginUserBO;
import com.lsc.fegin.entity.FeginUserDO;
import com.lsc.fegin.service.FeginUserService;

import io.seata.spring.annotation.GlobalTransactional;

@Service
public class FeginUserServiceImpl implements FeginUserService {
	
	@Autowired
	private FeginUserBO feginUserBO;
	@Autowired
	UserService userService;
	
	@Transactional
	@Override
	public boolean save() {
		// 操作1
		FeginUserDO user1 = new FeginUserDO();
		user1.setId("111111");
		user1.setUserName("操作1");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");// 设置日期格式
		user1.setUserPassword(sdf.format(new Date()));
		return feginUserBO.save(user1);
	}
	
	@GlobalTransactional(rollbackFor = Exception.class)
	@Override
	public boolean callAdminInsert() {
		System.out.println("执行分布式事务测试");
		userService.dtpInsertUser();
		this.save();
		Integer.valueOf("ab");
		return true;
	}
}
